/*
	栈的链式存储，是受运算限制的单链表。其插入和删除操作只能在表头位置上进行。
	top为链表的头指针

*/
typedef int ElemType;
typedef int Status;
typedef int ERROR;
typedef int OK;

typedef struct stacknode
{
	ElemType data;
	struct StackNode *next;
}StackNode;


/*
	初始条件判断为 head -> next ==NULL
*/
StackNode *Init_LinkStack(void)
{
	StackNode *top;
	top = (StackNode *)malloc(sizeof(stacknode));
	top -> next = NULL;
	return(top);
}

/*
	压栈
*/
Status push(StackNode *top,ElemType e)
{
	StackNode *p;
	p = (StackNode *)malloc(sizeof(StackNode));
	if (!p)
		return ERROR;
	p -> data = e;
	p -> next = top -> next;
	top -> next = p;
	return OK;
}

/*
	弹栈
*/
Sattus pop(StackNode *top,ElemType *e)
{//将栈顶元素弹出
	StackNode *p;
	if (top -> next == NULL)
		return ERROR;
	p = top->next;
	e = p -> data;
	top -> next = p -> next;
	free(p);
	return OK;
}


